import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:web_socket_channel/io.dart';

class WebSocketData extends ChangeNotifier {
  late final IOWebSocketChannel _channel;

  IOWebSocketChannel get websocketChannel {
    return _channel;
  }

  void initWebsocketChannel() async {
    final prefs = await SharedPreferences.getInstance();
    String? token = prefs.getString("user-token");
    _channel = IOWebSocketChannel.connect(
        'ws://192.168.0.106:8081/dailoz_war/websocket/socketServer',
        headers: {
          "http.version": "HTTP/1.1",
          "Upgrade": 'websocket',
          "Connection": "upgrade",
          "Authorization": token,
        });
    _channel.stream.listen((event) {
      print(event);
    });
    notifyListeners();
  }

  void disposeWebsocketChannel() {
    // WebSocketService.websocketDispose(_channel);
  }
}
